home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 8
/
Aminet 8 (1995)(GTI - Schatztruhe)[!][Oct 1995].iso
/
Aminet
/
text
/
hyper
/
gmake.lha
/
gmake
/
c_source
/
file.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-08-22
|
4KB
|
195 lines
// file commands
#include "standard.h"
#define feq(a) if(comp_str(type,a))
static FILE * gm; // gmakefile
static BOOL gfile_open=FALSE;
static FILE * gf // guidefile
static BOOL guide_open=FALSE;
static FILE * cf; // currentfile
static BOOL current_open=FALSE;
txt_to_guide(char * msg)
{
fprintf(gf,"%s\n",msg)
}
file_to_guide()
{
int buffer;
if(!current_open)
return;
REM ("Copying current file to guide");
for (buffer = fgetc(cf); buffer !=EOF; buffer = fgetc(cf))
{
fputc(buffer,gf)
}
}
BOOL open_file(char * filename)
{
NOTE ("Opening File: ",filename);
if((cf = fopen(filename,"r")) == NULL)
{
MTEXT error_msg;
sprintf(error_msg, "Unable to open file: %s", filename);
perr(error_msg);
current_open = FALSE;
}
else {current_open = TRUE;}
return current_open;
}
close_file()
{
if(!current_open)
return;
fclose(cf);
REM ("Closing current file");
current_open = FALSE;
}
BOOL open_gmakefile(char * gmakefile)
{
NOTE ("gmakefile: ",gmakefile);
if((gm = fopen(gmakefile,"r")) == NULL)
{
perr("Unable to open gmakefile.");
gfile_open = FALSE;
}
else {gfile_open = TRUE;}
return gfile_open;
}
BOOL open_guidefile()
{
MTEXT guidefile;
strcpy (guidefile,getfilename(GUIDE));
NOTE ("guidefile: ",guidefile);
if((gf = fopen(guidefile,"w")) == NULL)
{
perr("Unable to open guidefile.");
guide_open = FALSE;
}
else {guide_open = TRUE;}
return guide_open;
}
getdata_gmakefile()
{
MTEXT buffer;
BOOL do_loop=TRUE;
while(do_loop)
{
if(fgets(buffer, BUFLEN, gm)==NULL)
{
REM("End of GMAKEFILE");
do_loop = FALSE;
}
else
{
MTEXT type; // Which type of file it is
MTEXT file; // The name of the file
MTEXT arg; // Any extra information
MTEXT trash; // S__t
strcpy(trash,"");strcpy(file,"");strcpy(arg,""); // Make null
sscanf(buffer,"%[^:]%[: \t]%[^\n]", type, trash, file);
// Find out the type of command..
if(type[0] == ';')
{
// Comments
}
else feq("Guide")
{
add_type(GUIDE,file,"");
}
else feq("PreMain")
{
add_type(PRE,file,"");
}
else feq("PostMain")
{
add_type(POST,file,"");
}
else feq("PreFace")
{
add_type(PREFACE,file,"Preface");
}
else feq("Disclaimer")
{
add_type(DISC,file,"Distribution Disclaimer");
}
else feq("About")
{
add_type(ABOUT,file,"About the distribution");
}
else feq("Author")
{
add_type(AUTHOR,file,"About the author");
}
else feq("Install")
{
add_type(INSTALL,file,"How to install the files");
}
else feq("Usage")
{
add_type(USAGE,file,"How to use the package");
}
else feq("Bugs")
{
add_type(BUGS,file,"Bugs in the system");
}
else feq("History")
{
add_type(HISTORY,file,"History");
}
else feq("Page")
{
if(fgets(buffer, BUFLEN, gm)==NULL)
{
REM ("End of GMAKEFILE with page");
do_loop = FALSE;
}
else
{
sscanf(buffer,"%[ \t]%[^\n]", trash, arg);
add_type(PAGE,file,arg);
}
}
else
{
REM("Not a recognised type");
}
}
}
}
close_files()
{
if (gfile_open)
fclose(gm);
if (guide_open)
fclose(gf);
}
init_guidefile()
{
REM ("putting the initial information into the guide file.");
fprintf(gf,"@database %s\n",getfilename(GUIDE));
fprintf(gf, "@author The Amiga Guide Compiler\n"
"@(c) Copyright © 1995 Gary Greenhill\n"
"@wordwrap\n");
}